package ex3.controller.date;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;

/**
 * @AUTHOR 尹书岿
 * @DATE 2024/12/11 15:50
 * @DESCRIBE
 */
public class Date3 {
    public static void main(String[] args) {
        String Strdate = "2024-12-15";
        LocalDate localDate = LocalDate.parse(Strdate);
        //计算出当月第一天是日历的星期几
        int dayOfWeek = localDate.plusDays(1-localDate.getDayOfMonth()).getDayOfWeek().getValue();
        int day = localDate.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
        System.out.println(dayOfWeek);
        System.out.println(day);

        int[] arr = new int[42]; //6*7
        int count = 1;
        for (int i = dayOfWeek; i < day + dayOfWeek; i++) {
            arr[i] = count++;
        }
        System.out.println(Arrays.toString(arr));

        int today = localDate.getDayOfMonth();
        System.out.println(today);

        System.out.println("一\t二\t三\t四\t五\t六\t日");

        //遍历输出日历
        for (int i = 1; i < arr.length; i++){
            if (arr[i] == 0){
                System.out.print("\t");
            }
            else {
                if (arr[i] == today){
                    System.out.print("*");
                }
                System.out.print(arr[i]+"\t");
            }
            if (i % 7 == 0) {
                System.out.println();
            }
        }
    }
}
